#include <cstdio>
#include <algorithm>

typedef long long ll;
const int maxn=300000;

class Ele {
    public:
        ll f, a, b;
};

class Heap {
    public:
        int id[maxn+1], map[maxn+1], size;
        ll a[maxn+1], b[maxn+1];

        bool cmp(int x, int y) {return (double)a[x]/b[x]<=(double)a[y]/b[y];}

        void swap(int x, int y) {
            std::swap(id[x], id[y]);
            std::swap(a[x], a[y]), std::swap(b[x], b[y]);
            map[id[x]]=x, map[id[y]]=y;
        }

        void up(int o) {
            if (o>1 && cmp(o, o/2)) {
                swap(o, o/2);
                up(o/2);
            }
        }

        void down(int o) {
            if (((o*2<size && cmp(o*2, o*2+1)) || o*2==size) && cmp(o*2, o)) {
                swap(o*2, o);
                down(o*2);
            } else if (o*2<size && cmp(o*2+1, o*2) && cmp(o*2+1, o)) {
                swap(o*2+1, o);
                down(o*2+1);
            }
        }

        void push(ll va, ll vb, int x) {
            size++;
            a[size]=va, b[size]=vb, id[size]=x;
            map[x]=size;
            up(size);
        }

        void pop(int pos) {
            swap(pos, size);
            map[id[size]] = 0;
            if (--size) down(pos);
            up(pos);
        }
};

class Set {
    public:
        int f[maxn+1];

        void init(int n) {
            for (int i=1; i<=n; i++) f[i]=i;
        }

        int getFa(int o) {return f[o]==o ? o : f[o]=getFa(f[o]);}

        void merge(int u, int v) {
            u=getFa(u), v=getFa(v);
            if (u!=v) f[v]=u;
        }
};

int main() {
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);

    static bool vis[maxn+1], mer[maxn+1];
    static int f[maxn+1];
    static Heap heap;
    static Set set;
    int n;
    scanf("%d", &n);
    set.init(n);
    for (int i=2; i<=n; i++) scanf("%d", f+i);
    for (int i=1; i<=n; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        heap.push(a, b, i);
    }

    vis[0] = true;
    ll ans=0, a=0, b=0;
    for (; heap.size; ) {
        int id=heap.id[1], fa=set.getFa(f[id]);
        // int id=heap.id[1], fa;
        // for (fa=f[id]; mer[fa]; fa=f[fa]);
        if (vis[fa]) {
            ans += b*heap.a[1];
            a+=heap.a[1], b+=heap.b[1];
            vis[id] = true;
            heap.pop(1);
        } else {
            ll na=heap.a[heap.map[fa]],
                nb=heap.b[heap.map[fa]];
            ans += nb*heap.a[1];
            na+=heap.a[1], nb+=heap.b[1];
            set.merge(fa, id);
            // mer[id] = true;
            heap.pop(heap.map[fa]);
            heap.pop(1);
            heap.push(na, nb, set.getFa(id));
            // heap.push(na, nb, fa);
        }
    }
    printf("%lld\n", ans);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
